#include "ModelManager.h"

ModelManager::ModelManager(void)
:Manager("FigureManager"),
Component("FigureManager")
{
}

void ModelManager::addedToObject()
{
    requestMessage("AddModel",&ModelManager::AddModel);
    requestMessage("FindModel",&ModelManager::FindModel);
}

ModelManager::~ModelManager(void)
{
}

void ModelManager::AddModel(const Message &msg)
{
    LOAD_MSG;
    MODEL ml;
    string name=boost::any_cast<string>(*iter++);
    ml.name=name;
    AddObj(ml);
}

void ModelManager::Log()
{
}

void ModelManager::FindModel(const Message &msg)
{
    foreach(&ModelManager::MyFunc,msg.p);
}

bool ModelManager::MyFunc(MODEL m,boost::any any)
{
    vector<boost::any> tmp=boost::any_cast<vector<boost::any>>(any);
    vector<boost::any>::iterator iter=tmp.begin();
    string mname=boost::any_cast<string>(*iter++);
    int32* mid=boost::any_cast<int32*>(*iter++);
    if(m.name==mname)
    {
        *mid=m.GetID();
        return true;
    }
    else
        return false;
}